Skip to content

fix(core): raise RecipientNotFoundError instead of generic Exception for unknown recipients - #8063

Open
Siddhesh Kabra (Xsidz) wants to merge 3 commits into
microsoft:mainfrom
Xsidz:fix/recipient-not-found-exception
Open

fix(core): raise RecipientNotFoundError instead of generic Exception for unknown recipients#8063
Siddhesh Kabra (Xsidz) wants to merge 3 commits into
microsoft:mainfrom
Xsidz:fix/recipient-not-found-exception

Conversation

@Xsidz

Copy link
Copy Markdown

Summary

Fixes #4964

When send_message is called with an agent type that is not registered in the runtime, the runtime now raises RecipientNotFoundError instead of a bare Exception("Recipient not found"). This lets callers catch the specific error class rather than parsing the error message string.

Changes:

  • Added RecipientNotFoundError to autogen_core/exceptions.py
  • Exported RecipientNotFoundError from autogen_core.__init__ so it is accessible as from autogen_core import RecipientNotFoundError
  • Updated _single_threaded_agent_runtime.py to raise RecipientNotFoundError at the point where recipient lookup fails
  • Added a test in test_runtime.py that verifies RecipientNotFoundError is raised for unregistered agent types

Test plan

  • New test test_send_message_to_unregistered_agent_raises_recipient_not_found passes
  • Full packages/autogen-core/tests/ suite passes (225 tests, 0 failures)
  • RecipientNotFoundError is importable directly from autogen_core
  • RecipientNotFoundError is also accessible via autogen_core.exceptions.RecipientNotFoundError

…for unknown recipients

Fixes microsoft#4964

When send_message is called with an unregistered agent type, the runtime now raises
RecipientNotFoundError (from autogen_core.exceptions) instead of a bare Exception,
allowing callers to handle this case without matching on the error string.
Copilot AI lite review requested due to automatic review settings August 16, 2026 12:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Xsidz

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

1 similar comment
@Xsidz

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Python] Fine-grained exception class for "recipient not found" in Core

2 participants